const { tool,time,api } = getApp();
Page({

    data: {
        open_id: '',        // 学生 id
        page: 0,            // 页码
        pagesize: 10,       // 单页数据量
        list: [],           // 周报列表
        isLoding: false,    // 是否可加载
    },

    // 查看详情
    jump(e) {
        let { id } = e.currentTarget.dataset;
        api.navigateTo(`/pages/user/report/details/index?id=${id}`)
    },

    // 获取数据
    getData() {
        let { open_id,page,pagesize,list } = this.data;
        tool.getMyReport({ open_id,page,pagesize }).then(res => {
            for(let item of res) {
                item.startTime = time.split(item.startTime);
                item.endTime = time.split(item.endTime);
            }
            list.push(...res);
            this.setData({ list,isLoding: res.length == pagesize });
        })
    },

    // 页面加载
    onLoad(options) {
        tool.getUserInfo().then(info => {
            this.setData({ open_id: info.open_id });
            this.getData();
        })
    },

    // 上拉加载
    onReachBottom() {
        let { isLoding,page } = this.data;
        if (isLoding) {
            page++;
            this.setData({ page })
            this.getData();
        } else api.showToast('暂无更多数据','none');
    },
    
})